import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule,ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { ProductComponent } from './product/product.component';
import { productdataService } from './shared/productdata.service';
import { Product1Component } from './product1/product1.component';
import { loggerService } from './shared/logger.service';
import { AnotherProductdataService } from './shared/another-productdata.service';
import { BindComponent } from './bind/bind.component';
import { OberComponent } from './ober/ober.component';
import { MypipPipe } from './pipe/mypip.pipe';
import { OrderComponent } from './order/order.component';
import { PriceQuoteComponent } from './price-quote/price-quote.component';
import { LifeComponent } from './life/life.component';
import { ChildComponent } from './child/child.component';
import { FormsComponent } from './forms/forms.component';
import { ReactiveFormsComponent } from './reactive-forms/reactive-forms.component';
import { ReactiveRegisterComponent } from './reactive-register/reactive-register.component';
import { MobileValidatorDirective } from './directive/mobile-validator.directive';
import { EqualValidatorDirective } from './directive/equal-validator.directive';
import { ProductByNodeDataComponent } from './product-by-node-data/product-by-node-data.component';


@NgModule({
  declarations: [
    AppComponent,
    ProductComponent,
    Product1Component,
    BindComponent,
    OberComponent,
    MypipPipe,
    OrderComponent,
    PriceQuoteComponent,
    LifeComponent,
    ChildComponent,
    FormsComponent,
    ReactiveFormsComponent,
    ReactiveRegisterComponent,
    MobileValidatorDirective,
    EqualValidatorDirective,
    ProductByNodeDataComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule
  ],
  // providers: [productdataService,loggerService],
  providers:[
    {
      provide:productdataService,
      useFactory:(logger:loggerService,App_Config) => {
          // let dev = Math.random() > 0.5;
          if(App_Config.isDev){
            return new productdataService(logger);
          }else{
            return new AnotherProductdataService(logger);
          }
      },
      deps:[loggerService,'App_Config']
    },
    loggerService,
    {
      provide:'App_Config',useValue:{isDev:true}
    }    
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }
